<<<<<<< HEAD
package com.regpang.alumniassociation.wheelview;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

import com.regpang.alumniassociation.R;
import com.regpang.alumniassociation.wheelview.libs.ArrayWheelAdapter;
import com.regpang.alumniassociation.wheelview.libs.WheelView;

import java.util.ArrayList;


public class TextPopupWindow extends PopupWindow implements OnClickListener {


    private View rootView;
    private View btnSubmit, btnCancel;
    private ArrayList<String> list;

    private WheelView wheelView;

    private static final String TAG_SUBMIT = "submit";
    private static final String TAG_CANCEL = "cancel";
    private OnTextSelectListener textSelectListener;

    public TextPopupWindow(Context context, ArrayList<String> list, int currentItem) {
        super(context);
        this.list = list;
        this.setWidth(LayoutParams.MATCH_PARENT);
        this.setHeight(LayoutParams.MATCH_PARENT);
        this.setBackgroundDrawable(new ColorDrawable(0xb0000000));
        this.setOutsideTouchable(true);
        this.setAnimationStyle(R.style.timepopwindow_anim_style);

        LayoutInflater mLayoutInflater = LayoutInflater.from(context);
        rootView = mLayoutInflater.inflate(R.layout.text_popupwindow_textview, null);


        btnSubmit = rootView.findViewById(R.id.btnSubmit);
        btnSubmit.setTag(TAG_SUBMIT);
        btnCancel = rootView.findViewById(R.id.btnCancel);
        btnCancel.setTag(TAG_CANCEL);

        wheelView = (WheelView) rootView.findViewById(R.id.address_picker);

        btnSubmit.setOnClickListener(this);
        btnCancel.setOnClickListener(this);

        wheelView.setAdapter(new ArrayWheelAdapter<>(list));
        wheelView.setCurrentItem(currentItem);

        int textSize = context.getResources().getDimensionPixelSize(R.dimen.wheel_text_size);

        wheelView.TEXT_SIZE = textSize;

        setContentView(rootView);

        rootView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                int height = rootView.findViewById(R.id.id_pop_text_ly).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });
    }


    public void showAtLocation(View parent, int gravity, int x, int y) {
        super.showAtLocation(parent, gravity, x, y);
    }


    @Override
    public void onClick(View v) {
        String tag = (String) v.getTag();
        if (tag.equals(TAG_CANCEL)) {
            dismiss();
            return;

        } else {
            if (textSelectListener != null) {
                textSelectListener.onTextSelect(list.get(wheelView.getCurrentItem()), wheelView.getCurrentItem());
            }
            dismiss();
            return;
        }
    }

    public interface OnTextSelectListener {
        void onTextSelect(String text, int position);
    }

    public void setOnTextSelectListener(OnTextSelectListener textSelectListener) {
        this.textSelectListener = textSelectListener;
    }

}
=======
package com.regpang.alumniassociation.wheelview;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

import com.regpang.alumniassociation.R;
import com.regpang.alumniassociation.wheelview.libs.ArrayWheelAdapter;
import com.regpang.alumniassociation.wheelview.libs.WheelView;

import java.util.ArrayList;


public class TextPopupWindow extends PopupWindow implements OnClickListener {


    private View rootView;
    private View btnSubmit, btnCancel;
    private ArrayList<String> list;

    private WheelView wheelView;

    private static final String TAG_SUBMIT = "submit";
    private static final String TAG_CANCEL = "cancel";
    private OnTextSelectListener textSelectListener;

    public TextPopupWindow(Context context, ArrayList<String> list, int currentItem) {
        super(context);
        this.list = list;
        this.setWidth(LayoutParams.MATCH_PARENT);
        this.setHeight(LayoutParams.MATCH_PARENT);
        this.setBackgroundDrawable(new ColorDrawable(0xb0000000));
        this.setOutsideTouchable(true);
        this.setAnimationStyle(R.style.timepopwindow_anim_style);

        LayoutInflater mLayoutInflater = LayoutInflater.from(context);
        rootView = mLayoutInflater.inflate(R.layout.text_popupwindow_textview, null);


        btnSubmit = rootView.findViewById(R.id.btnSubmit);
        btnSubmit.setTag(TAG_SUBMIT);
        btnCancel = rootView.findViewById(R.id.btnCancel);
        btnCancel.setTag(TAG_CANCEL);

        wheelView = (WheelView) rootView.findViewById(R.id.address_picker);

        btnSubmit.setOnClickListener(this);
        btnCancel.setOnClickListener(this);

        wheelView.setAdapter(new ArrayWheelAdapter<>(list));
        wheelView.setCurrentItem(currentItem);

        int textSize = context.getResources().getDimensionPixelSize(R.dimen.wheel_text_size);

        wheelView.TEXT_SIZE = textSize;

        setContentView(rootView);

        rootView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                int height = rootView.findViewById(R.id.id_pop_text_ly).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });
    }


    public void showAtLocation(View parent, int gravity, int x, int y) {
        super.showAtLocation(parent, gravity, x, y);
    }


    @Override
    public void onClick(View v) {
        String tag = (String) v.getTag();
        if (tag.equals(TAG_CANCEL)) {
            dismiss();
            return;

        } else {
            if (textSelectListener != null) {
                textSelectListener.onTextSelect(list.get(wheelView.getCurrentItem()), wheelView.getCurrentItem());
            }
            dismiss();
            return;
        }
    }

    public interface OnTextSelectListener {
        void onTextSelect(String text, int position);
    }

    public void setOnTextSelectListener(OnTextSelectListener textSelectListener) {
        this.textSelectListener = textSelectListener;
    }

}
>>>>>>> 12b9a08f9380bce72b8c6e055d4084faa0570803
